package handler;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyHandlerEX02{

    @ExceptionHandler({RuntimeException.class})

    /**
     * 处理运行时异常
     */
    public ModelAndView handlerRuntimeException(RuntimeException e){
        e.printStackTrace();
        ModelAndView mav = new ModelAndView();
        mav.addObject("errorMSG","运行时异常");
        mav.setViewName("/error.jsp");

        return mav;
    }

    /**
     * 其他异常
     * @param e
     * @return
     */
    public ModelAndView handlerOtherException(RuntimeException e){
        e.printStackTrace();
        ModelAndView mav = new ModelAndView();
        mav.addObject("errorMSG","其他异常");
        mav.setViewName("/error.jsp");

        return mav;
    }
}
